package academic.ui.server;
import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
 * 
 */
public class GWTService extends RemoteServiceServlet
{
	private static final long serialVersionUID = 1760091498169075663L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		String className;
		className = request.getRequestURI().replaceAll("(.*\\/|\\.gwt$)", "");
		
		try
		{
			SocoGWTServlet servlet = (SocoGWTServlet) Class.forName(className).newInstance();
			
			if (servlet.authorize(request))
			{
				servlet.init(this.getServletConfig());
				servlet.service(request,response);
			}
		}
		catch (Exception ex)
		{
			super.service(request, response);
		}
	}
	
	ServletConfig config;
	
	@Override
	public void init(ServletConfig config) throws ServletException
	{
		super.init(config);
		String className = config.getInitParameter("konaEngineClass");
		
		try
		{
			SocoGWTServlet servlet = (SocoGWTServlet) Class.forName(className).newInstance();
			servlet.init(this.getServletConfig());		
		}
		catch (Exception ex)
		{
			
		}
	}
}
